home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / mus / play / multiplsr.lha / play8.asm < prev    next >
Assembly Source File  |  1992-09-14  |  10KB  |  425 lines

  1. * MultiPlayer
  2. * Copyright (C) 1992 Bryan Ford
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * I (the author of MultiPlayer) can be contacted on the Internet at
  19. * "bryan.ford@m.cc.utah.edu".  See "Player.doc" for other addresses.
  20. *
  21. * $Id: play8.asm,v 3.1 92/05/25 07:52:25 BAF Exp $
  22. *
  23.  
  24.         include "exec/types.i"
  25.         include "exec/execbase.i"
  26.         include "hardware/custom.i"
  27.         include "hardware/dmabits.i"
  28.         include "hardware/intbits.i"
  29.         include "bry/macros.i"
  30.  
  31.         ifnd    custom
  32. custom  equ     $dff000
  33.         endc
  34.  
  35. BUFLEN       equ     632
  36.  
  37.  STRUCTURE      VirtChan,0
  38.         APTR    vc_sample
  39.         UWORD   vc_subpos
  40.         UWORD   vc_length
  41.         LABEL   vc_pos
  42.         UWORD   vc_posfrac
  43.         UWORD   vc_posint
  44.         LABEL   vc_inc
  45.         UWORD   vc_incint
  46.         UWORD   vc_incfrac
  47.         APTR    vc_relsample
  48.         UWORD   vc_rellength
  49.         UWORD   vc_bufper
  50.         LABEL   vc_SIZEOF
  51.  
  52.  STRUCTURE      HardwareChan,0
  53.         APTR    hc_audcustom
  54.         APTR    hc_playbuf
  55.         APTR    hc_fillbuf
  56.         LABEL   hc_DEFSIZEOF
  57.         STRUCT  hc_virtchan0,vc_SIZEOF
  58.         STRUCT  hc_virtchan1,vc_SIZEOF
  59.         UWORD   hc_channum
  60.         UWORD   hc_buflend2
  61.         LABEL   hc_SIZEOF
  62.  
  63.         xref    _SysBase,intflashsample
  64.  
  65.         xdef    p8_Start,p8_Stop
  66.         xdef    p8_SetPeriod,p8_SetVolume
  67.         xdef    p8_PlaySample,p8_Release,p8_StopSample
  68.         xdef    p8_AudioInt
  69.  
  70.         code    text
  71.  
  72. *** Initialize and start the audio engine
  73. * d0 = Sampling period for combining channels (>= 127 FIXME???)
  74. p8_Start:
  75.         push    d2-d3
  76.  
  77.         ml      #3579545,d2
  78.         divu.w  d0,d2
  79.         cq      d3
  80.         mw      d2,d3
  81.         divu.w  #50*2,d3
  82.  
  83.         lea     hc0,a0                  ; Reset the data structures
  84.         lea     custom+aud0,a1
  85.         mw      d0,d1
  86.         cq      d0
  87.         bsr.b   \clrhc
  88.         bsr.b   \clrhc
  89.         bsr.b   \clrhc
  90.         bsr.b   \clrhc
  91.  
  92.         bsr     p8_AudioInt             ; Prime the pump, clear everything out
  93.         bsr     p8_AudioInt
  94.  
  95.         mw      #DMAF_SETCLR!DMAF_AUDIO,custom+dmacon   ; Start playing
  96.  
  97.         pop     d2-d3
  98.         rts
  99.  
  100. \clrhc
  101.         mw      d3,hc_buflend2(a0)
  102.         clr.w   hc_virtchan0+vc_length(a0)
  103.         mw      d1,hc_virtchan0+vc_bufper(a0)
  104.         clr.w   hc_virtchan1+vc_length(a0)
  105.         mw      d1,hc_virtchan1+vc_bufper(a0)
  106.         mw      d0,hc_channum(a0)
  107.  
  108.         push    a0/d3                   ; Tell MultiPlayer where to find the data
  109.         ml      hc_fillbuf(a0),a0
  110.         add.w   d3,d3
  111.         mw      d3,d2
  112.         bsr     intflashsample
  113.         pop     a0/d3
  114.  
  115.         addq.w  #1,d0
  116.         lea     hc_SIZEOF(a0),a0
  117.         mw      d1,ac_per(a1)
  118.         mw      d3,ac_len(a1)
  119.         mw      #$40,ac_vol(a1)
  120.         lea     aud1-aud0(a1),a1
  121.         rts
  122.  
  123. *** Stop the audio engine
  124. p8_Stop:
  125.         mw      #DMAF_AUDIO,custom+dmacon
  126.         rts
  127.  
  128. findchan macro
  129.         add.w   d0,d0
  130.         add.w   d0,d0
  131.         ml      virtchantab(pc,d0.w),a1
  132.         endm
  133.  
  134. *** Set the period of a virtual channel
  135. * d0 = Virtual channel number (0-7)
  136. * d1 = Period (greater than bufper)
  137. p8_SetPeriod:
  138.         findchan
  139.         tst.w   d1
  140.         bz.s    9$
  141.         cq      d0
  142.         mw      vc_bufper(a1),d0
  143.         divu.w  d1,d0
  144.         mw      d0,vc_incint(a1)
  145.         clr.w   d0
  146.         divu.w  d1,d0
  147.         mw      d0,vc_incfrac(a1)
  148. 9$      rts
  149.  
  150. virtchantab:
  151.         dc.l    hc0+hc_virtchan0,hc0+hc_virtchan1
  152.         dc.l    hc1+hc_virtchan0,hc1+hc_virtchan1
  153.         dc.l    hc2+hc_virtchan0,hc2+hc_virtchan1
  154.         dc.l    hc3+hc_virtchan0,hc3+hc_virtchan1
  155.  
  156. *** Start a new note/sample in a channel
  157. * d0 = Virtual channel number (0-7)
  158. * a0 = Sample (in fast memory if possible)
  159. * d1 = Length of sample (not including 632 byte suffix)
  160. * d2 = Length of repeat part of sample (0 = one-shot)
  161. p8_PlaySample:
  162.         findchan
  163.         ml      a0,vc_sample(a1)
  164.         mw      d1,vc_length(a1)
  165.         mw      d2,d1
  166.         bnz.b   1$
  167.         mw      #$ffff,d1
  168. 1$      mw      d1,vc_subpos(a1)
  169.         clr.l   vc_pos(a1)
  170.         rts
  171.  
  172. *** Begin the release phase of a sample
  173. * d0 = Virtual channel number (0-7)
  174. * a0 = Release part of sample (just after 632 byte prefix)
  175. * d1 = Length of repeat part (not including 632 byte prefix or 632 byte suffix)
  176. p8_Release:
  177.         findchan
  178.         illegal
  179.  
  180. *** Stop a channel
  181. * d0 = Virtual channel number (0-7)
  182. p8_StopSample:
  183.         findchan
  184.         clr.w   vc_length(a1)
  185.         rts
  186.  
  187. *** Set the volume of a virtual channel
  188. *** Note: Setting the volume for one virtchan sets the volume for the entire hardchan.
  189. * d0 = Virtual channel number (0-7)
  190. * d1 = Volume ($00-$40)
  191. p8_SetVolume:
  192.         lsr.w   #1,d0
  193.         lsl.w   #4,d0
  194.         lea     custom+aud+ac_vol,a0
  195.         adda.w  d0,a0
  196.         mw      d1,(a0)
  197.         rts
  198.  
  199. ld0     macro
  200.         ml      hc_virtchan0+vc_sample(a6),a0
  201.         suba.w  d7,a0
  202.         ml      hc_virtchan0+vc_pos(a6),d2
  203.         add.w   d7,d2
  204.         ml      hc_virtchan0+vc_inc(a6),d4
  205.         endm
  206.  
  207. ld1     macro
  208.         ml      hc_virtchan1+vc_sample(a6),a1
  209.         suba.w  d7,a1
  210.         ml      hc_virtchan1+vc_pos(a6),d3
  211.         add.w   d7,d3
  212.         ml      hc_virtchan1+vc_inc(a6),d5
  213.         endm
  214.  
  215. sv0     macro
  216.         add.w   d7,d2
  217. \svb0\@ cmp.w   hc_virtchan0+vc_length(a6),d2
  218.         blo.b   \sv0\@
  219.         sub.w   hc_virtchan0+vc_subpos(a6),d2
  220.         bhs.b   \svb0\@
  221.         clr.w   hc_virtchan0+vc_length(a6)
  222. \sv0\@  ml      d2,hc_virtchan0+vc_pos(a6)
  223.         endm
  224.  
  225. sv1     macro
  226.         add.w   d7,d3
  227. \svb1\@ cmp.w   hc_virtchan1+vc_length(a6),d3
  228.         blo.b   \sv1\@
  229.         sub.w   hc_virtchan1+vc_subpos(a6),d3
  230.         bhs.b   \svb1\@
  231.         clr.w   hc_virtchan1+vc_length(a6)
  232. \sv1\@  ml      d3,hc_virtchan1+vc_pos(a6)
  233.         endm
  234.  
  235. comb01  macro
  236.         move.b  0(a1,d3.w),(a2)+
  237.         swap    d3
  238.         add.l   d5,d3
  239.         swap    d3
  240.         endm
  241.  
  242. comb10  macro
  243.         move.b  0(a0,d2.w),(a2)+
  244.         swap    d2
  245.         add.l   d4,d2
  246.         swap    d2
  247.         endm
  248.  
  249. comb11  macro
  250.         move.b  0(a0,d2.w),d0
  251.         add.b   0(a1,d3.w),d0
  252.         move.b  d0,(a2)+
  253.         swap    d2
  254.         swap    d3
  255.         add.l   d4,d2
  256.         add.l   d5,d3
  257.         swap    d2
  258.         swap    d3
  259.         endm
  260.  
  261. *** Audio interrupt routine - call after updating song
  262. p8_AudioInt:
  263.         push    d2-d7/a2-a6
  264.         lea     hc0,a6
  265.         bsr.b   \upchan
  266.         lea     hc_SIZEOF(a6),a6
  267.         bsr.b   \upchan
  268.         lea     hc_SIZEOF(a6),a6
  269.         bsr.b   \upchan
  270.         lea     hc_SIZEOF(a6),a6
  271.         bsr.b   \upchan
  272.         pop     d2-d7/a2-a6
  273.         move.w  #INTF_AUD0!INTF_AUD1!INTF_AUD2!INTF_AUD3,custom+intreq
  274.         rts
  275.  
  276. \upchan
  277.         ml      hc_audcustom(a6),a5
  278.  
  279.         ml      hc_fillbuf(a6),d0
  280.         ml      hc_playbuf(a6),a2
  281.         ml      a2,ac_ptr(a5)
  282.         ml      a2,hc_fillbuf(a6)
  283.         ml      d0,hc_playbuf(a6)
  284.  
  285.         mw      #$8000,d7
  286.  
  287.         tst.w   hc_virtchan0+vc_length(a6)
  288.         bz      \f0
  289. \f1
  290.         tst.w   hc_virtchan1+vc_length(a6)
  291.         bz      \f1s0
  292.  
  293. \f1s1
  294.         ld0
  295.         ld1
  296.         mw      hc_buflend2(a6),d1
  297.         mw      d1,d6
  298.         lsr.w   #2,d1
  299.         bra     11$
  300. 1$      comb11
  301.         comb11
  302.         comb11
  303.         comb11
  304.         comb11
  305.         comb11
  306.         comb11
  307.         comb11
  308. 11$     dbra    d1,1$
  309.         andi.w  #3,d6
  310.         bra     13$
  311. 12$     comb11
  312.         comb11
  313. 13$     dbra    d6,12$
  314.         sv0
  315.         sv1
  316.         rts
  317.  
  318. \f1s0
  319.         ld0
  320.         mw      hc_buflend2(a6),d1
  321.         mw      d1,d6
  322.         lsr.w   #2,d1
  323.         bra     21$
  324. 2$      comb10
  325.         comb10
  326.         comb10
  327.         comb10
  328.         comb10
  329.         comb10
  330.         comb10
  331.         comb10
  332. 21$     dbra    d1,2$
  333.         andi.w  #3,d6
  334.         bra     23$
  335. 22$     comb10
  336.         comb10
  337. 23$     dbra    d6,22$
  338.         sv0
  339.         rts
  340.  
  341. \f0
  342.         tst.w   hc_virtchan1+vc_length(a6)
  343.         bz      \f0s0
  344.  
  345. \f0s1
  346.         ld1
  347.         mw      hc_buflend2(a6),d1
  348.         mw      d1,d6
  349.         lsr.w   #2,d1
  350.         bra     51$
  351. 5$      comb01
  352.         comb01
  353.         comb01
  354.         comb01
  355.         comb01
  356.         comb01
  357.         comb01
  358.         comb01
  359. 51$     dbra    d1,5$
  360.         andi.w  #3,d6
  361.         bra     53$
  362. 52$     comb01
  363.         comb01
  364. 53$     dbra    d6,52$
  365.         sv1
  366.         rts
  367.  
  368. \f0s0
  369.         mw      hc_buflend2(a6),d1
  370.         add.w   d1,d1
  371.         lea     0(a2,d1.w),a0
  372.         cq      d2
  373.         cq      d3
  374.         cq      d4
  375.         cq      d5
  376.         ml      d2,a2
  377.         ml      d3,a3
  378.         ml      d4,a4
  379.         ml      d5,a5
  380.         mw      hc_buflend2(a6),d1
  381.         mw      d1,d6
  382.         andi.w  #15,d6
  383.         bra     73$
  384. 72$     mw      d2,-(a0)
  385. 73$     dbra    d6,72$
  386.         lsr.w   #4,d1
  387.         bra     71$
  388. 7$      movem.l d2-d5/a2-a5,-(a0)
  389. 71$     dbra    d1,7$
  390.         rts
  391.  
  392.         data    play8data
  393.  
  394. hc0     dc.l    custom+aud0,soundbuf0,soundbuf1
  395.         ds.b    hc_SIZEOF-hc_DEFSIZEOF
  396.  
  397. hc1     dc.l    custom+aud1,soundbuf2,soundbuf3
  398.         ds.b    hc_SIZEOF-hc_DEFSIZEOF
  399.  
  400. hc2     dc.l    custom+aud2,soundbuf4,soundbuf5
  401.         ds.b    hc_SIZEOF-hc_DEFSIZEOF
  402.  
  403. hc3     dc.l    custom+aud3,soundbuf6,soundbuf7
  404.         ds.b    hc_SIZEOF-hc_DEFSIZEOF
  405.  
  406.         bss     chip,chip
  407.  
  408. soundbuf0       ds.b    BUFLEN
  409.                 cnop    0,4
  410. soundbuf1       ds.b    BUFLEN
  411.                 cnop    0,4
  412. soundbuf2       ds.b    BUFLEN
  413.                 cnop    0,4
  414. soundbuf3       ds.b    BUFLEN
  415.                 cnop    0,4
  416. soundbuf4       ds.b    BUFLEN
  417.                 cnop    0,4
  418. soundbuf5       ds.b    BUFLEN
  419.                 cnop    0,4
  420. soundbuf6       ds.b    BUFLEN
  421.                 cnop    0,4
  422. soundbuf7       ds.b    BUFLEN
  423.  
  424.         end
  425.